<%- partial('../sidebar') %>
<div id='content' ng-controller="FileCtrl">
  <div class="panel">
    <div class="header">
      <% [['all', '全部文件', 'fa fa-navicon'], ['category', '按照类型', 'fa fa-th-large'], ['my', '我的上传', 'fa fa-upload']].forEach(function (pair) {
        var value = pair[0];
        var text = pair[1];
        var icon = pair[2]; %>
        <a href="<%= value ? '/files/?tab=' + value : '/' %>"
          class="topic-tab <%= value === tab ? 'current-tab' : '' %>"><i class="<%= icon %> mr5"></i><%= text %></a>
      <% }) %>
    </div>
    <div class="inner file_list ng-cloak" style="display:none;">
      <% if(tab === 'all' || tab === 'my') { %>
      <div class="nav_dir">
        <strong>当前目录：</strong>
        <span ng-if="dir.tree.length > 1"><a href="javascript:void(0)" ng-click="list(dir.tree[dir.tree.length - 2])">返回上一级</a>&nbsp;|&nbsp;</span>
        <span ng-repeat="subdir in dir.tree">
          <span ng-if="$index < dir.tree.length - 1"><a href="javascript:void(0)" ng-click="list(subdir)">{{subdir.name | formatDir}}</a>&nbsp;&gt;&nbsp;</span>
          <span ng-if="$index === dir.tree.length - 1">{{subdir.name | formatDir}}</span>
        </span>
        <input name="rootDir" type="hidden" value="<%= rootDir %>" />
      </div>
      <% } %>
      <div>
        <table class="table table-hover">
          <thead>
            <tr>
              <th class="w3p"><input type="checkbox" ng-change="toggleAllSelect(this)" ng-model="selectAll" /></th>
              <th class="w30p">文件名</th>
              <th class="w30p">关联任务</th>
              <th class="w7p">大小</th>
              <th class="w13p">更改人</th>
              <th class="w17p">更新日期</th>
            </tr>
          </thead>
          <tbody>
            <tr ng-if="fileList.length === 0" class="warning">
              <td colspan="6"><strong><i class="fa fa-warning mr5"></i>当前目录下没有文件！</strong></td>
            <tr>
            <tr ng-repeat="file in fileList">
              <td><input type="checkbox" ng-model="file.selected" /></td>
              <td>
                <i class="fa {{file | fileIcon}} fa-lg file_icon mr5"></i>
                <a href="/files/{{file._id}}" ng-if="file.type!=='_dir_'">{{file.name}}</a>
                <a href="javascript:void(0)" ng-if="file.type==='_dir_'" ng-click="list(file)">{{file.name}}</a>
              </td>
              <td><a href="">{{file.task}}</a></td>
              <td>{{file.size | formatFileSize}}</td>
              <td>{{file.user.loginname}}</td>
              <td>{{file.update_time | date:'yyyy-MM-dd HH:mm'}}</td>
            </tr>
          </tbody>
        </table>
        <div id="fileUpload">
          <div class="btn btn-default" ng-file-select ng-model="files" ng-multiple="true" allow-dir="true" accept="" ng-change="upload(files)"><i class="fa fa-upload mr5"></i>上传文件</div>
        </div>
        <div id="createDir">
          <button type="button" class="btn btn-primary" ng-click="createDir()"><i class="fa fa-folder-o mr5"></i>创建目录</button>
          <input type="text" ng-model="dirname" />
        </div>
        <div>
          <button type="button" class="btn btn-danger" ng-click="removeFiles()"><i class="fa fa-trash-o mr5"></i>删除文件</button>
        </div>
      </div>
    </div>
  </div>
  <div class="modal fade" id="uploadFileModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">文件上传 - {{uploadFileList.length}}个文件</h4>
        </div>
        <div class="modal-body">
          <p ng-if="uploadFileStatus === 'done'" class="alert alert-info">
            <span ng-if="uploadFileSuccessCount > 0">上传成功<strong>{{uploadFileSuccessCount}}</strong>个文件<br/></span>
            <span ng-if="uploadFileList.length - uploadFileSuccessCount > 0">上传失败：<strong>{{uploadFileList.length - uploadFileSuccessCount}}</strong>个文件&nbsp;&nbsp;&nbsp;&nbsp;请检查网络连接或者文件是否重名<br/></span>
            <span>将在{{countDown}}秒自动关闭</span>
          </p>
          <div class="list-group">
            <div class="list-group-item" ng-repeat="file in uploadFileList">
              
              <p class="list-group-item-heading">{{file.name}}</p>
              <div class="list-group-item-text">
                <div class="progress progress-info progress-striped active" ng-if="file.status === 'progress'">
                  <div class="bar" role="progressbar" style="width: {{file.percentage}}%">{{file.percentage}}%</div>
                </div>
                <div class="progress progress-success progress-striped" ng-if="file.status === 'ok'">
                  <div class="bar" role="progressbar" style="width: 100%"><i class="fa fa-check mr5"></i>文件上传成功</div>
                </div>
                <div class="progress progress-danger progress-striped" ng-if="file.status === 'fail'">
                  <div class="bar" role="progressbar" style="width: 100%"><i class="fa fa-check mr5"></i>文件上传失败，请检查网络连接或者文件是否重名</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
</div>

<!-- scripts -->
  <%- Loader('/public/index.min.js')
  .js('/public/libs/underscore-min.js')
  .js('/public/libs/angular.min.js')
  .js('/public/libs/angular-file-upload.min.js')
  .js('/public/javascripts/file.js')
  .done(assets, config.site_static_host, config.mini_assets)
  %>

<script type="text/javascript">

</script>